/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.birrap.webservicebirrap.service;

import com.birrap.webservicebirrap.BaresCervezasTapasVasosT;
import com.birrap.webservicebirrap.BaresCervezasTapasVasosTPK;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.PathSegment;

/**
 *
 * @author Denver
 */
@Stateless
@Path("com.birrap.webservicebirrap.barescervezastapasvasost")
public class BaresCervezasTapasVasosTFacadeREST extends AbstractFacade<BaresCervezasTapasVasosT> {
    @PersistenceContext(unitName = "com.birrap_WebServiceBirrap_war_1.0-SNAPSHOTPU")
    private EntityManager em;

    private BaresCervezasTapasVasosTPK getPrimaryKey(PathSegment pathSegment) {
        /*
         * pathSemgent represents a URI path segment and any associated matrix parameters.
         * URI path part is supposed to be in form of 'somePath;idBar=idBarValue;idCerveza=idCervezaValue;idTapa=idTapaValue;idVaso=idVasoValue'.
         * Here 'somePath' is a result of getPath() method invocation and
         * it is ignored in the following code.
         * Matrix parameters are used as field names to build a primary key instance.
         */
        com.birrap.webservicebirrap.BaresCervezasTapasVasosTPK key = new com.birrap.webservicebirrap.BaresCervezasTapasVasosTPK();
        javax.ws.rs.core.MultivaluedMap<String, String> map = pathSegment.getMatrixParameters();
        java.util.List<String> idBar = map.get("idBar");
        if (idBar != null && !idBar.isEmpty()) {
            key.setIdBar(new java.lang.Integer(idBar.get(0)));
        }
        java.util.List<String> idCerveza = map.get("idCerveza");
        if (idCerveza != null && !idCerveza.isEmpty()) {
            key.setIdCerveza(new java.lang.Integer(idCerveza.get(0)));
        }
        java.util.List<String> idTapa = map.get("idTapa");
        if (idTapa != null && !idTapa.isEmpty()) {
            key.setIdTapa(new java.lang.Integer(idTapa.get(0)));
        }
        java.util.List<String> idVaso = map.get("idVaso");
        if (idVaso != null && !idVaso.isEmpty()) {
            key.setIdVaso(new java.lang.Integer(idVaso.get(0)));
        }
        return key;
    }

    public BaresCervezasTapasVasosTFacadeREST() {
        super(BaresCervezasTapasVasosT.class);
    }

    @POST
    @Override
    @Consumes({"application/xml", "application/json"})
    public void create(BaresCervezasTapasVasosT entity) {
        super.create(entity);
    }

    @PUT
    @Override
    @Consumes({"application/xml", "application/json"})
    public void edit(BaresCervezasTapasVasosT entity) {
        super.edit(entity);
    }

    @DELETE
    @Path("{id}")
    public void remove(@PathParam("id") PathSegment id) {
        com.birrap.webservicebirrap.BaresCervezasTapasVasosTPK key = getPrimaryKey(id);
        super.remove(super.find(key));
    }

    @GET
    @Path("{id}")
    @Produces({"application/xml", "application/json"})
    public BaresCervezasTapasVasosT find(@PathParam("id") PathSegment id) {
        com.birrap.webservicebirrap.BaresCervezasTapasVasosTPK key = getPrimaryKey(id);
        return super.find(key);
    }

    @GET
    @Override
    @Produces({"application/xml", "application/json"})
    public List<BaresCervezasTapasVasosT> findAll() {
        return super.findAll();
    }

    @GET
    @Path("{from}/{to}")
    @Produces({"application/xml", "application/json"})
    public List<BaresCervezasTapasVasosT> findRange(@PathParam("from") Integer from, @PathParam("to") Integer to) {
        return super.findRange(new int[]{from, to});
    }

    @GET
    @Path("count")
    @Produces("text/plain")
    public String countREST() {
        return String.valueOf(super.count());
    }

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }
    
}
